#include "GmSSLServer.h"
#include "GmSSLServantImp.h"

//#define _TG_DEBUG

#ifdef _TG_DEBUG
	#include "TGGmSSL.h"
	#include <iostream>
#endif

using namespace std;

GmSSLServer g_app;

/////////////////////////////////////////////////////////////////
void
GmSSLServer::initialize()
{
	//initialize application here:
	//...

	addServant<GmSSLServantImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".GmSSLServantObj");
}
/////////////////////////////////////////////////////////////////
void
GmSSLServer::destroyApp()
{
	//destroy application here:
	//...
}
/////////////////////////////////////////////////////////////////
int
main(int argc, char* argv[])
{
	#ifdef _TG_DEBUG
		pair<string, string> keys = sm2_genKey();
		string public_key = keys.first;
		string private_key = keys.second;

		cout << "public_key:" << endl;
		cout << public_key << endl;
		cout << "private_key:" << endl;
		cout << private_key << endl;

		string sign_out = sm2_sign(private_key, "123456", "admin");

		cout << "sign result:" << sign_out << endl;

		int verify_ret = sm2_verify(public_key, "123456", sign_out, "admin");

		cout << "verify:" << verify_ret << endl;
	#else
		try
		{
			g_app.main(argc, argv);
			g_app.waitForShutdown();
		}
		catch (std::exception& e)
		{
			cerr << "std::exception:" << e.what() << std::endl;
		}
		catch (...)
		{
			cerr << "unknown exception." << std::endl;
		}
		return -1;
	#endif
}
/////////////////////////////////////////////////////////////////
